package cn.xuewenbao.edu.service.impl;

import cn.xuewenbao.edu.entity.CourseChapter;
import cn.xuewenbao.edu.mapper.CourseChapterMapper;
import cn.xuewenbao.edu.service.CourseChapterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mafayu
 * @since 2021-04-07
 */
@Service
@Slf4j
public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, CourseChapter> implements CourseChapterService {

    //根据章节id删除课程章节
    @Override
    public Result<?> deleteChapter(String chapterId) {
        Result<?> result = new Result<>();
        int count = baseMapper.deleteById(chapterId);
        if (count == 0) {
            result.setSuccess(false);
            result.setMessage("删除章节失败");
            return result;
        }
        result.setSuccess(true);
        result.setMessage("删除章节成功");
        return result;
    }

    //根据课程id删除章节
    @Override
    public void deleteChapterByCourseId(String courseId) {
        QueryWrapper<CourseChapter> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id", courseId);
        int count = baseMapper.delete(wrapper);
        if (count == 0) {
            log.error("删除章节失败");
        }
    }

}
